<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of ModuleNavigation
 *
 * @author dejo
 */
class Tc_Helper_ModuleNavigation extends Zend_Controller_Action_Helper_Abstract {

    public function preDispatch() {
        $bootstrap = $this->getActionController()->getInvokeArg('bootstrap');

        $layout = $bootstrap->layout;
        $view = $layout->getView();

        $module = $this->getRequest()->getModuleName();

        if(empty($module)) {
            $module = "default";
        }

        if(file_exists(APPLICATION_PATH . '/configs/' . strtolower($module) . '_navigation.xml')) {
            $navConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/' . strtolower($module) . '_navigation.xml', 'nav');
            $container = new Zend_Navigation($navConfig);

            $role = Zend_Auth::getInstance()->getStorage()->read()->role;
            if(!$role) {
                $role = 'guest';
            }
            $view->navigation($container)->setAcl(new Tc_Acl())->setRole($role);
            $partial = array('menu.phtml', 'admin');
            $view->navigation()->menu()->setPartial($partial);
        }
    }
}
?>
